#!/bin/sh

. "$TEST_SHELL_PATH/backup/abstract-backup"

shell_unit_test() {
  echo 0 > "$TEST_TARGET_PATH/lock_annotation_count"
  shell_unit_test_backup
}

mock kubectl kubectl_mock_overwrite

kubectl_mock_overwrite() {
  mokked
  case "$*" in
    ("annotate sgclusters.stackgres.io "*)
    local ANNOTATION_COUNT="$(cat "$TEST_TARGET_PATH/lock_annotation_count")"
    echo "$((ANNOTATION_COUNT + 1))" > "$TEST_TARGET_PATH/lock_annotation_count"
    if [ "$ANNOTATION_COUNT" = 1 ]
    then
      return 1
    fi
    ;;
    ("get $BACKUP_CRD_NAME -n $CLUSTER_NAMESPACE --template=$BACKUP_CR_TEMPLATE")
    sleep 1
    ;;
    *)
    not_mokked
    ;;
  esac
}
